﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Follow_inc.aspx.cs" Inherits="newBlog.CenterInc.view_inc.Follow_inc" %>
<%@ Import Namespace="newBlog.CenterInc.Ctrltor" %>
<% Response.ContentType = "application/json";
    if (Session["user_id"]==null) {
        Response.Write("{\"error\":\"您未登录本站\"}");
        return;
    }
    
    int mode = Request.QueryString["mode"] == null || Request.QueryString["mode"].Length == 0 ? 0 : Convert.ToInt32(Request.QueryString["mode"]);//1关注 2取消关注
    string user_id = Session["user_id"].ToString();
    string follow_fans_id = Request.Form["follow_fans_id"]==null||Request.Form["follow_fans_id"].Length==0?"":Request.Form["follow_fans_id"];
    fans_follow_inc fans_Follow_Inc = new fans_follow_inc();
    switch (mode) {
        case 1:
            if (follow_fans_id.Length==0) {
                Response.Write("{\"error\":\"不能留空\"}");
                return;
            }
            if(fans_Follow_Inc.SelectisFollow(user_id,follow_fans_id)){
                Response.Write("{\"error\":\"您已经关注过了不能重复关注\"}");
                return;
            }
            if (fans_Follow_Inc.Follow(user_id,follow_fans_id)) {
                Response.Write("{\"error\":\"关注失败\"}");
                return;
            }
            Response.Write("{\"msg\":\"关注成功\"}");
            return;
        case 2:
            if (follow_fans_id.Length==0) {
                Response.Write("{\"error\":\"不能留空\"}");
                return;
            }
            if(!fans_Follow_Inc.SelectisFollow(user_id,follow_fans_id)){
                Response.Write("{\"error\":\"您没有关注此人不能取消关注\"}");
                return;
            }
            if (fans_Follow_Inc.delFollow(user_id,follow_fans_id)) { 
            Response.Write("{\"error\":\"取消关注失败\"}");
                return;
            }
            Response.Write("{\"msg\":\"您已成功取消关注\"}");
            return;
    }
    %>
